# Concave
# Copyright (C) 2012 Daniel Malmqvist
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import pygame
import os
class Sounds():
    def __init__(self):
        self.sounds = dict()
        self.musicTracks = dict()
        
        self.musicId = 0
        pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
        self.loadSounds()
        
    def loadSounds(self):
        self.sounds[0] = pygame.mixer.Sound(os.path.join("sounds","scissors-cutting-paper-2.ogg"))
        self.sounds[1] = pygame.mixer.Sound(os.path.join("sounds","scissors-cutting-paper-1.ogg"))
        self.musicTracks[0] = os.path.join("sounds","Calmtown.ogg")
        self.musicTracks[1] = os.path.join("sounds","sea.ogg")
        self.musicTracks[2] = os.path.join("sounds","trouble loop.ogg")
    
    def playSound(self, soundId):
        channel = pygame.mixer.Channel(soundId%2)
        channel.play(self.sounds[soundId])
    
    def playMusic(self, musicTrackId):
        self.musicId = musicTrackId
        pygame.mixer.music.load(self.musicTracks[musicTrackId])
        pygame.mixer.music.play(-1)
        
    def getCurrentMusicTrack(self):
        return self.musicId
    
    def stop(self):
        pygame.mixer.music.stop()